package com.sixth.volunteerservicesystem.Controller;

import com.sixth.volunteerservicesystem.Service.IBackendProjectService;
import com.sixth.volunteerservicesystem.Service.IBackendUserinfoService;
import com.sixth.volunteerservicesystem.domain.CURDResult;
import com.sixth.volunteerservicesystem.domain.PageResult;
import com.sixth.volunteerservicesystem.domain.Project;
import com.sixth.volunteerservicesystem.domain.Users;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/backend")
public class BackendIndexController {
    @Autowired(required=false)
    IBackendUserinfoService backendUserinfoService;

    @Autowired(required=false)
    IBackendProjectService backendProjectService;

    @RequestMapping("")
    public String backend() {
        return "backend/backend_index";
    }

    // 负责打通userinfo这一模块
    @RequestMapping("/userinfo")
    public String backendinfo() {
        return "backend/backend_userinfo";
    }

    // 负责打通userinfo这一模块
    @RequestMapping("/project")
    public String backendProjectinfo() {
        return "backend/backend_project";
    }

    // 在userinfo这一模块中显示志愿者信息
    @RequestMapping("/userinfoJson")
    @ResponseBody
    public PageResult<Users> backendUserinfoJson(int page, int limit) {
        PageResult<Users> result = backendUserinfoService.findUserPageResult(null, page, limit);
        System.out.println(result.toString());
        return result;
    }

    // 在userinfo这一模块中显示志愿者信息
    @RequestMapping("/projectJson")
    @ResponseBody
    public PageResult<Project> backendprojectJson(int page, int limit) {
        PageResult<Project> result = backendProjectService.findProjectPageResult(null, page, limit);
        return result;
    }


    @RequestMapping("/userinfoadd")
    public String backendUserinfoadd() {
        return "backend/backend_userinfo_add";
    }

    // 双击弹框，显示志愿者信息数据
    @RequestMapping("userinfodetail")
    public String userinfodetail(Model model, String userId) {
        Users user = backendUserinfoService.findUserByuserId(userId);
        model.addAttribute("user",user);
        return "backend/backend_userinfo_detail";
    }

    // 双击弹框，显示项目数据
    @RequestMapping("projectdetail")
    public String projectdetail(Model model, String formId) {
        Project project = backendProjectService.findProjectById(formId);
        System.out.println(project);
        model.addAttribute("project",project);
        return "backend/backend_project_detail";
    }

    @RequestMapping("/userinfosave")
    @ResponseBody
    public CURDResult backendUserinfosave(Users user) {
        CURDResult result = new CURDResult();
        System.out.println(user);
        backendUserinfoService.userinfosave(user);
        return result;
    }




}
